//
//  RMMDaShangView.m
//  Romomo
//
//  Created by puman on 2016/10/26.
//  Copyright © 2016年 mazegong. All rights reserved.
//

#import "RMMDaShangView.h"

@implementation RMMDaShangView
{
    UIView *_view;
}
- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
        
        _view = [[UIView alloc] initWithFrame:CGRectMake(kScreenWideth / 2 - 135, 150, 270, 270)];
        _view.backgroundColor = kBasicColor;
        _view.layer.masksToBounds = YES;
        _view.layer.cornerRadius =  kRow;
        [self addSubview:_view];
        
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, _view.width, 54)];
        label.text = @"天干物燥,美容 技师 去买杯饮料吧";
        label.textColor = COLORFROMCODE(0xFFFFFF, 1);
        label.textAlignment = NSTextAlignmentCenter;
        label.font = kFont(14);
        [_view addSubview:label];
        
        UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(0, 54, _view.width, _view.height - 54)];
        backView.backgroundColor =  kWhiteColor;
        [_view addSubview:backView];
        
        NSArray *array = @[@"5元",@"10元",@"20元"];
        for (int i = 0; i < 3; i++) {
            UIButton  *button = [UIButton buttonWithType:(UIButtonTypeCustom)];
            button.frame = CGRectMake((backView.width - 180 - 20) / 2 + 70 *  i, kMaric, 60, 32);
            button.tag = 50 + i;
            button.layer.cornerRadius = 16;
            button.layer.borderColor = kBasicColor.CGColor;
            [button setTitleColor:kBasicColor forState:(UIControlStateNormal)];
            [button setTitle:array[i] forState:(UIControlStateNormal)];
            button.titleLabel.font  = kFont(14);
            button.layer.borderWidth = 1;
            [backView addSubview:button];
        }
        _textF = [[UITextField alloc] initWithFrame:CGRectMake(16, backView.height - 140 , backView.width - 32, 76)];
        _textF.backgroundColor = kCColor;
        _textF.placeholder  = @"输入任意金额";
        _textF.font = kFont(18);
        _textF.clearButtonMode = UITextFieldViewModeWhileEditing;
        _textF.keyboardType =  UIKeyboardTypeNumberPad;
        _textF.textAlignment = NSTextAlignmentCenter;
        [backView addSubview:_textF];
        
        RMMKeyBoardAccessoryView *accessoryView  =  [[RMMKeyBoardAccessoryView alloc] initWithFrame:CGRectMake(0, 0, kScreenWideth, 42)];
        BUTTON_S(accessoryView.doneBut, doneBut);
        _textF.inputAccessoryView = accessoryView;

        UIView  *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, backView.height  - 49, backView.width, 0.5)];
        lineView.backgroundColor  = COLORFROMCODE(0xEEEEEE, 1);
        [backView addSubview:lineView];
        
        _button = [UIButton buttonWithType:(UIButtonTypeCustom)];
        _button.frame  = CGRectMake(0, lineView.bottom, backView.width, backView.height - lineView.bottom);
        [_button setTitle:@"打赏" forState:(UIControlStateNormal)];
        [_button setTitleColor:COLORFROMCODE(0xB5B5B5, 1) forState:(UIControlStateNormal)];
        _button.backgroundColor = kWhiteColor;
        _button.userInteractionEnabled = NO;
        [backView addSubview:_button];
    }
    return self;
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    UITouch *touch = [touches anyObject];
    CGPoint point = [touch locationInView:self];
    CGFloat x = point.x;
    CGFloat y = point.y;
    if ( !((x >= _view.left && x <= _view.right) && (y >= _view.top && y <= _view.bottom))) {
        [_textF resignFirstResponder];
        [UIView animateWithDuration:kInterval animations:^{
            self.frame = CGRectMake(0, kScreenHeight, kScreenWideth, kScreenHeight);
        } completion:^(BOOL finished) {
            
        }];
    }
}
- (void)doneBut{
    [_textF resignFirstResponder];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
